﻿using System.IO;
using System.Reflection;
using System.Xml.Linq;

namespace UnitTest
{
    public class TestingBase
    {

        protected const string WP_EXPORT_XML_FILE_NAME = "wordpress_export.xml";
        /// <summary>
        /// Load XML file from embeded resources.
        /// </summary>
        /// <param name="fileName">File name.</param>
        /// <returns>Returns loaded Xml Element.</returns>
        protected XElement GetXmlFromFile(string fileName)
        {
            // need to provide namespce and file name for the embeded resource.
            const string UNIT_TEST_NAMESPACE = "UnitTest.";
            string fullName = UNIT_TEST_NAMESPACE + fileName;
            XElement xElement = null;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName))
            {
                if (stream != null)
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        xElement = XElement.Parse(sr.ReadToEnd());
                    }
                }
            }

            return xElement;
        }

        private XElement GetXElement()
        {
            XElement xml = this.GetXmlFromFile("wordpress_export.xml");
            return xml;
        }

    }
}
